﻿using System;
using System.Collections.Generic;
using ParserGenerator.Collections;

namespace ParserGenerator.Extensions
{
    public static class ISetExtensions
    {
        public static ReadOnlySet<T> AsReadOnly<T>(this ISet<T> set)
        {
            if (set == null)
                throw new ArgumentNullException(nameof(set));
            return new ReadOnlySet<T>(set);
        }

        public static int GetSetHashCode<T>(this ISet<T> set)
        {
            if (set == null)
                throw new ArgumentNullException(nameof(set));
            int h = 0;
            foreach (T item in set)
            {
                int c = ICollectionExtensions.GetItemHashCode(item);
                h ^= c & 0x7fffffff;
            }
            return h;
        }
    }
}
